/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * MonthPlanItemVisitor.java
 * business
 * 2013-1-4下午5:14:10
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.report.visitor;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.MonthPlanningItem;
import org.jackysoft.entity.Product;
import org.jackysoft.report.ItemUnit;
import org.springframework.stereotype.Component;

@Component
public class MonthPlanItemVisitor implements Visitor {

	
	private static final Log logger = LogFactory.getLog(MonthPlanItemVisitor.class);
	private Map<String,Double> itemValue;
		
	@Override
	public Double getValue() throws NoSuchMethodException {
		return null;
	}

	@Override
	public void visite(ItemUnit item) {
		if(item==null) return;
		if(itemValue==null){
			logger.error("请设置当月完成数变量", new IllegalStateException("当月完成数据集未设置 "+itemValue));
			
		}
		MonthPlanningItem mitem = (MonthPlanningItem) item;
		
		Product host =  mitem.getHost();
		if(host==null){
			logger.info("计划项是顶级子项   "+mitem);
			host = mitem.getOwner();
		}
		if(host==null){
			
			throw new IllegalStateException("对于计划项至少需要存在owner属性或者host");
		}
	
		Double fval = itemValue.get(host.getCode());
	    mitem.setCompleted(fval);
	    
	}

	@Override
	public void starup() {
		// TODO Auto-generated method stub
		
	}

	public void setItemValue(Map<String,Double> itemValue) {
		this.itemValue = itemValue;
	}

}
